import {
  Component,
  OnInit,
  Input,
  Output,
  EventEmitter,
  Inject
} from "@angular/core";
import * as _ from "lodash";
@Component({
  selector: "app-select-area-range",
  templateUrl: "./select-area-range.component.html",
  styleUrls: ["./select-area-range.component.scss"]
})
export class SelectAreaRangeComponent implements OnInit {
  @Input()
  type = "area";

  @Input()
  onRange: any;

  @Output()
  onChange: EventEmitter<any> = new EventEmitter();

  private start: any = {};
  private end: any = {};

  constructor(@Inject("UtilsService") private utilsService) {}

  ngOnInit() {}

  onChangeStart(e) {
    this.start = e;
    this.triggerChange();
  }

  triggerChange() {
    if (
      !this.utilsService.isEmptyObj(this.start) &&
      !this.utilsService.isEmptyObj(this.end)
    ) {
      this.onChange.emit({ start: this.start, end: this.end });
    }
  }

  onChangeEnd(e) {
    this.end = e;
    this.triggerChange();
  }
}
